package cn.miao.client;

import cn.miao.doc.CourseDoc;
import cn.miao.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @program: springcloud-hrm
 * @description: Course的降级方法
 * @author: MiaoWei
 * @create: 2021-11-27 21:28
 **/
@Component
@Slf4j
public class CourseESFeignClientFallbackFactory implements FallbackFactory<CourseESFeginClient> {
    @Override
    public CourseESFeginClient create(Throwable throwable) {
        throwable.printStackTrace();
        log.error("使用fegin调用Course课程失败,走到降级方法!");
        return new CourseESFeginClient() {

            @Override
            public AjaxResult save(CourseDoc courseDoc) {
                log.error("调用方法【{}】失败,原因:【{}】","save",throwable.getMessage());
                return AjaxResult.me().setSuccess(false);
            }

            @Override
            public AjaxResult remove(Long id) {
                log.error("调用方法【{}】失败,原因:【{}】","remove",throwable.getMessage());
                return AjaxResult.me().setSuccess(false);
            }

            @Override
            public AjaxResult search(Long id) {
                log.error("调用方法【{}】失败,原因:【{}】","searchOne",throwable.getMessage());
                return AjaxResult.me().setSuccess(false);
            }
        };
    }
}
